package com.mingqijia.gassafety.console.controller.inner;


import cn.hutool.json.JSONUtil;
import com.gap.basic.base.CommonResponse;
import com.mingqijia.gassafety.db.entity.vo.WorkOrderAndSmartKitVO;
import com.mingqijia.gassafety.webserver.request.console.sk.ConsoleSkNotifyAlarmRequest;
import com.mingqijia.gassafety.webserver.service.ConsoleSkNotifyAlarmService;
import com.mingqijia.gassafety.webserver.service.workorder.WorkOrderHistoryService;
import com.mingqijia.gassafety.webserver.webSocket.WebSocketProcess;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author solyutian
 * @date 2023/6/27 11:10
 * 智慧厨房报警通知接口
 */
@Slf4j
@Api(tags = "智慧厨房报警通知接口")
@RestController
@RequestMapping("/inner/v1/sk/notify")
public class ConsoleSkNotifyController {

  @Autowired
  ConsoleSkNotifyAlarmService service;

  @Autowired
  WorkOrderHistoryService workOrderHistoryService;

  @Autowired
  WebSocketProcess webSocketProcess;

  @ApiOperation("智慧厨房报警通知")
  @PostMapping(value = "/alarm", name = "智慧厨房报警通知")
  public CommonResponse<Object> alarm(@RequestBody ConsoleSkNotifyAlarmRequest request){
    return service.alarm(request);
  }


  @GetMapping(value = "/aaa", name = "智慧厨房报警通知")
  public CommonResponse<Object> aaa(@RequestParam String id){
    List<String> ids = new ArrayList<>();
    ids.add(id);
    List<WorkOrderAndSmartKitVO> workOrderAndSmartKitVOS = workOrderHistoryService
        .selectWorkOrderAndSmartKitByRecordId(ids);
    log.info("补充说明:{}", JSONUtil.toJsonStr(workOrderAndSmartKitVOS));
    return CommonResponse.success(workOrderAndSmartKitVOS);
  }

  @GetMapping("/bbb")
  public CommonResponse timeOut() throws InterruptedException {
    TimeUnit.SECONDS.sleep(30);
    return CommonResponse.success("成功");
  }

  @PostMapping(value = "/ccc", name = "智慧厨房报警通知")
  public CommonResponse<Object> ccc(@RequestParam String spId,@RequestBody Object request){
    webSocketProcess.redisTopicSendMsg(spId,JSONUtil.toJsonStr(request));
    return CommonResponse.success(null);
  }


}
